/**
 * QIBAO Service Inc
 * All Rights Reserved @2019
 */
package com.qibao.toolkit.util;

import java.util.Optional;

/**
 * <p>应用版本信息.</p>
 *
 * @author zhanghui
 * @version $Id: AppVersion.java, v0.1 2019/9/19 11:10 zhanghui Exp $$
 */
public class AppVersion {

    private String appName;

    private String appVersion;

    public AppVersion(Class<?> mainClass) {
        this.appName = Optional.ofNullable(mainClass).map(cls -> Optional.ofNullable(cls.getPackage().getImplementationTitle()).orElse("not found app name")).orElse("not found main class");
        this.appVersion = Optional.ofNullable(mainClass).map(cls -> Optional.ofNullable(cls.getPackage().getImplementationVersion()).orElse("not found app version")).orElse("not found main class");
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public void setAppVersion(String appVersion) {
        this.appVersion = appVersion;
    }

    @Override
    public String toString() {
        return "AppVersion{" +
                "appName='" + appName + '\'' +
                ", appVersion='" + appVersion + '\'' +
                '}';
    }
}
